/*
 *  Composition0009.c
 *  SoundController0002
 *
 *  Created by jiro on 10/10/23.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "Composition0009.h"
#include "../sc/Common/WellTemperament.h"
#include "../sc/SoundController.h"

using namespace sc;

void Composition0009::Compose() {

	const double swell = 2;
	const double maxDynamics = 0.4;
	const double length0 = 16;

	double time;
	AudioRecorder32 recorder( 2, 1 );


	//	1 st chord
	{
		const double note1 = WellTemperament::GetFrequency( Note::C, -2 );
		const double note2 = WellTemperament::GetFrequency( Note::D, -1 );
		const double note3 = WellTemperament::GetFrequency( Note::G, -2 );
		const double note4 = WellTemperament::GetFrequency( Note::B, -1 );	
		const double note5 = WellTemperament::GetFrequency( Note::C, -2 ) + 1 / swell;  
		const SoundElement32* element1 = SoundGenerator::Generate( note1, length0, maxDynamics ); 
		const SoundElement32* element2 = SoundGenerator::Generate( note2, length0, maxDynamics ); 
		const SoundElement32* element3 = SoundGenerator::Generate( note3, length0, maxDynamics ); 
		const SoundElement32* element4 = SoundGenerator::Generate( note4, length0, maxDynamics ); 
		const SoundElement32* element5 = SoundGenerator::Generate( note5, length0, maxDynamics / 4 ); 

		time = 0;
		recorder.Record( 0, 0, time, element1, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element2, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element3, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element4, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element5, 0.5, 0.5 );
	}

	//	2nd chord
	{
		const double note1 = WellTemperament::GetFrequency( Note::EFlat, -2 );
		const double note2 = WellTemperament::GetFrequency( Note::F, -1 );
		const double note3 = WellTemperament::GetFrequency( Note::BFlat, -2 );
		const double note4 = WellTemperament::GetFrequency( Note::D, -1 );
		const double note5 = WellTemperament::GetFrequency( Note::EFlat, -2 ) + 1 / swell;  
		const SoundElement32* element1 = SoundGenerator::Generate( note1, length0, maxDynamics ); 
		const SoundElement32* element2 = SoundGenerator::Generate( note2, length0, maxDynamics ); 
		const SoundElement32* element3 = SoundGenerator::Generate( note3, length0, maxDynamics ); 
		const SoundElement32* element4 = SoundGenerator::Generate( note4, length0, maxDynamics ); 
		const SoundElement32* element5 = SoundGenerator::Generate( note5, length0, maxDynamics / 4 ); 

		time = 8;
		recorder.Record( 0, 0, time, element1, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element2, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element3, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element4, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element5, 0.5, 0.5 );

	}

	recorder.OutputAudioFile( kAudioFileWAVEType, "a_00009.wav" );
}